package com.ziri.quartz.cluster.config;

import com.ziri.quartz.cluster.entity.BaseLabel;
import com.ziri.quartz.cluster.service.BaseLabelService;
import com.ziri.quartz.cluster.service.QuartzService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Order(value = 1)
@Slf4j
public class ScheduledTaskRunner implements ApplicationRunner {

    //private final Logger log = LoggerFactory.getLogger(ScheduledTaskRunner.class);

    @Autowired
    BaseLabelService quartzTaskService;

    @Autowired
    QuartzService quartzService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info(" >>>>>> 项目启动完毕, 开启 => 需要自启的任务 开始!");
        List<BaseLabel> list= quartzTaskService.getAllLabel();
        quartzService.initAllTask(list);
        log.info(" >>>>>> 项目启动完毕, 开启 => 需要自启的任务 结束！");
    }
}
